package com.wenhui.schoolyardinfo.firstpage.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wenhui.schoolyardinfo.R;
import com.wenhui.schoolyardinfo.callback.RcvOnItemItemItemViewClickListener;
import com.wenhui.schoolyardinfo.firstpage.bean.SubcommentsBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author    : Urasaki
 * e-mail    : 1164688204@qq.com
 * date      : 2019/6/14 15:50
 * introduce : 子评论Adapter
 */

public class SubcommentsAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<SubcommentsBean> subcommentsBeanList = new ArrayList<>();

    public SubcommentsAdapter(Context context) {
        this.context = context;
    }

    public SubcommentsAdapter(Context context, List<SubcommentsBean> subcommentsBeanList) {
        this.context = context;
        this.subcommentsBeanList = subcommentsBeanList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_subcomment, null);
        return new ContentHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ContentHolder) {
            ContentHolder contentHolder = (ContentHolder) holder;
            contentHolder.tevFirstName.setText(subcommentsBeanList.get(position).getFirstName());
            contentHolder.tevSecondName.setText(subcommentsBeanList.get(position).getSecondName() + ":");
            contentHolder.tevSubcomment.setText(subcommentsBeanList.get(position).getSubcomment());
        }

    }

    @Override
    public int getItemCount() {
        return subcommentsBeanList.size();
    }

    protected class ContentHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        @BindView(R.id.tev_first_name)
        TextView tevFirstName;
        @BindView(R.id.tev_reply)
        TextView tevReply;
        @BindView(R.id.tev_second_name)
        TextView tevSecondName;
        @BindView(R.id.tev_subcomment)
        TextView tevSubcomment;

        public ContentHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

            tevFirstName.setOnClickListener(this);
            tevSecondName.setOnClickListener(this);
            tevSubcomment.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.tev_first_name:
                    rcvOnItemItemItemViewClickListener.onItemItemItemClickListener(getAdapterPosition(), view);
                    break;
                case R.id.tev_second_name:
                    rcvOnItemItemItemViewClickListener.onItemItemItemClickListener(getAdapterPosition(), view);
                    break;
                case R.id.tev_subcomment:
                    rcvOnItemItemItemViewClickListener.onItemItemItemClickListener(getAdapterPosition(), view);
                    break;
                default:
                    break;
            }
        }
    }

    private RcvOnItemItemItemViewClickListener rcvOnItemItemItemViewClickListener;

    public void setRcvOnItemItemItemViewClickListener(RcvOnItemItemItemViewClickListener rcvOnItemItemItemViewClickListener) {
        this.rcvOnItemItemItemViewClickListener = rcvOnItemItemItemViewClickListener;
    }
}
